home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / swtools / libdwarf / dwarf_alloc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  3.8 KB  |  138 lines

  1. /*
  2.  
  3.     dwarf_alloc.h
  4.     $Revision: 1.13 $    $Date: 1994/06/17 02:39:05 $
  5.  
  6. */
  7.  
  8. Dwarf_Ptr _dwarf_get_alloc (Dwarf_Debug, Dwarf_Small, Dwarf_Unsigned);
  9. Dwarf_Debug _dwarf_get_debug (void);
  10. Dwarf_Debug _dwarf_setup_debug (Dwarf_Debug);
  11. int _dwarf_free_all_of_one_debug (Dwarf_Debug);
  12.  
  13.  
  14. /*
  15.     This macro adds the size of a pointer to the size of a
  16.     struct that is given to it.  It rounds up the size to
  17.     be a multiple of the size of a pointer.  This is done
  18.     so that every struct returned by _dwarf_get_alloc()
  19.     can be preceded by a pointer to the chunk it came from.
  20.     Before, it checks if the size of struct is less than
  21.     the size of a pointer.  If yes, it returns the size
  22.     of 2 pointers.  The returned size should be at least
  23.     the size of 2 pointers, since the first points to the
  24.     chunk the struct was allocated from, and the second
  25.     is used to link the free list.
  26. */
  27. #define ROUND_SIZE_WITH_POINTER(a_struct) \
  28.     (sizeof(a_struct) < sizeof(void *) ? \
  29.     2 * sizeof(void *) : \
  30.         sizeof(a_struct) % sizeof(void *) == 0 ? \
  31.         sizeof(a_struct) + sizeof(void *) : \
  32.         sizeof(a_struct) + sizeof(void *) + sizeof(void *) -  \
  33.         (sizeof(a_struct) % sizeof(void *)))
  34.  
  35.  
  36. typedef struct Dwarf_Alloc_Area_s    *Dwarf_Alloc_Area;
  37. typedef struct Dwarf_Free_List_s    *Dwarf_Free_List;
  38.  
  39.  
  40. /* 
  41.     This struct is used to chain all the deallocated
  42.     structs on the free list of each chain.  The structs
  43.     are chained internally, by using the memory they
  44.     contain.
  45. */
  46. struct Dwarf_Free_List_s {
  47.     Dwarf_Free_List        fl_next;
  48. };
  49.  
  50.  
  51. /*
  52.     This struct is used to manage all the chunks malloc'ed
  53.     for a particular alloc_type.  Many of the fields are
  54.     initialized by dwarf_init().
  55. */
  56. struct Dwarf_Alloc_Hdr_s {
  57.  
  58.     /* Count of actual number of structs allocated. */
  59.     Dwarf_Sword            ah_struct_alloc_count;
  60.  
  61.     /* 
  62.         Size of each struct that will be allocated for
  63.         this alloc_type.  Initialized by dwarf_init().
  64.     */
  65.     Dwarf_Half            ah_alloc_size;
  66.  
  67.     /* 
  68.         Number of structs of this alloc_type that will
  69.         be contained in each chunk that is malloc'ed.
  70.         Initialized by dwarf_init().
  71.     */
  72.     Dwarf_Word            ah_alloc_num;
  73.  
  74.     /* 
  75.         Number of bytes malloc'ed per chunk, that is
  76.         ah_alloc_size * ah_alloc_num.
  77.     */
  78.     Dwarf_Word            ah_malloc_length;
  79.  
  80.     /* Count of chunks currently allocated for type. */
  81.     Dwarf_Sword            ah_curr_alloc;
  82.  
  83.         /* Max number of chunks ever allocated for type. */
  84.     Dwarf_Sword            ah_max_alloc;
  85.  
  86.     /* 
  87.         Points to a chain of Dwarf_Alloc_Area_s structs
  88.         that represent all the chunks currently allocated
  89.         for the alloc_type.
  90.     */
  91.     Dwarf_Alloc_Area        ah_alloc_area_head;
  92.  
  93.     /* Last Alloc Area that was allocated from. */
  94.     Dwarf_Alloc_Area        ah_last_alloc_area;
  95. };
  96.  
  97.  
  98. /*
  99.     This struct is used to manage each chunk that is
  100.     malloc'ed for a particular alloc_type.  For each
  101.     allocation type, the allocation header points to
  102.     a list of all the chunks malloc'ed for that type.
  103. */
  104. struct Dwarf_Alloc_Area_s {
  105.  
  106.     /* Points to the free list of structs in the chunk. */
  107.     Dwarf_Ptr        aa_free_list;
  108.  
  109.     /* 
  110.         Count of the number of free structs in the chunk.
  111.         This includes both those on the free list, and in
  112.         the blob.
  113.     */
  114.     Dwarf_Sword        aa_free_count;
  115.  
  116.     /* 
  117.         Points to the first byte of the blob from which
  118.         struct will be allocated.  A struct is put on the
  119.         free_list only when it dwrf_deallocated.  Initial
  120.         allocations are from the blob.
  121.     */
  122.     Dwarf_Small        *aa_blob_start;
  123.  
  124.     /* Points just past the last byte of the blob. */
  125.     Dwarf_Small        *aa_blob_end;
  126.  
  127.     /* Points to alloc_hdr this alloc_area is linked to. */
  128.     Dwarf_Alloc_Hdr    aa_alloc_hdr;
  129.  
  130.     /* 
  131.         Used for chaining Dwarf_Alloc_Area_s atructs. 
  132.         Alloc areas are doubly linked to enable deletion
  133.         from the list in constant time.
  134.     */
  135.     Dwarf_Alloc_Area    aa_next;
  136.     Dwarf_Alloc_Area    aa_prev;
  137. };
  138.